<template>
  <div class="content-wrap">
    <!-- 搜索区域 -->
    <div class="content-top">
      <el-form :inline="true" :model="formInline">
        <el-form-item label="姓名">
          <el-input
            placeholder="请输入内容"
            v-model="formInline.username"
          ></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-select placeholder="全部" v-model="formInline.sex">
            <el-option label="全部" value="全部" />
            <el-option label="男" value="男" />
            <el-option label="女" value="女" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" native-type="submit" @click="handleSearch"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 渲染搜索结果数据 -->
    <div class="content-menu">
      <!-- 添加测试 -->
      <el-button @click="addTestCase">
        <el-icon><Plus /></el-icon>
        <span>添加测试</span>
      </el-button>
      <!-- 测试用例表格 -->
      <el-table :data="tabelData" height="250" style="width: 100%">
        <el-table-column prop="id" label="序号" width="180">
          <template #default="scope">
            <div style="text-align: center">
              <span>{{ scope.row.id }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="姓名" width="280">
          <template #default="scope">
            <div style="text-align: center">
              <span>{{ scope.row.name }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="sex" label="性别" width="180">
          <template #default="scope">
            <div style="text-align: center">
              <span>{{ scope.row.sex }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="role" label="角色" width="180">
          <template #default="scope">
            <div style="text-align: center">
              <span>{{ scope.row.roleName }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="createAt" label="创建时间" width="280">
          <template #default="scope">
            <div style="text-align: center">
              <span>{{ new Date(scope.row.createAt).toLocaleString() }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="operation" label="操作" width="280">
          <template>
            <el-button @click="handleEdit()">
              <el-icon><Edit /></el-icon>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页组件 -->
    <div class="content-page">
      <Pagenation></Pagenation>
    </div>
    <!-- 弹出对话框 -->
    <el-dialog
      v-model="dialogControl"
      title="添加测试"
      width="600"
      draggable="true"
    >
      <el-form label-width="auto">
        <el-form-item label="姓名">
          <el-input palceholer="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-input palceholer="请输入性别"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="Cancel">取消</el-button>
          <el-button @click="Confirm">确认</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import { getRoleUsers } from "@/api/user/index";

let loading = ref(false); //加载效果
let dialogControl = ref(false); //弹窗控件
const tabelData = ref([]);
// 搜索关键词
const formInline = reactive({
  username: "",
  sex: "",
});

//* 获取所有用户
const getAllData = async () => {
  const resData = await getRoleUsers(0); // 0表示获取所有角色用户
  tabelData.value = resData.data;
};

//* 添加测试功能
const addTestCase = () => {
  // 开启弹窗
  dialogControl.value = true;
};
//* 点击搜索功能
const handleSearch = async () => {
  // 1、开启加载效果
  loading.value = true;

  // 2、搜索功能

  loading.value = false;
};

//* 修改功能
const handleEdit = () => {
};

//* 取消操作
const Cancel = () => {
};

//* 确认操作
const Confirm = () => {
};

onMounted(() => {
  getAllData();
});
</script>

<style scoped lang="scss">
.el-form {
  display: flex;
  justify-content: left;
  .el-form-item {
    margin-right: 20px;
  }
}
</style>
